import 'dart:convert' show json;

import '../user.dart';

class LikeList {
  LikeList({
    this.count,
    this.next,
    this.previous,
    this.results,
  });

  factory LikeList.fromJson(Map<String, dynamic> jsonRes) {
    if (jsonRes == null) {
      return null;
    }

    final List<MineLike> results =
    jsonRes['results'] is List ? <MineLike>[] : null;
    if (results != null) {
      for (final dynamic item in jsonRes['results']) {
        if (item != null) {
          results.add(MineLike.fromJson(asT<Map<String, dynamic>>(item)));
        }
      }
    }
    return LikeList(
      count: asT<int>(jsonRes['count']),
      next: asT<String>(jsonRes['next']),
      previous: asT<String>(jsonRes['previous']),
      results: results,
    );
  }

  int count;
  String next;
  String previous;
  List<MineLike> results;

  Map<String, dynamic> toJson() => <String, dynamic>{
    'count': count,
    'next': next,
    'previous': previous,
    'results': results,
  };

  @override
  String toString() {
    return json.encode(this);
  }
}

class MineLike {
  MineLike({
    this.instance_id,
    this.cover,
    this.user,
    this.content_type,
    this.like_num,
    this.comment_num,
    this.title,
  });

  factory MineLike.fromJson(Map<String, dynamic> jsonRes) => jsonRes == null
      ? null
      : MineLike(
    instance_id: asT<String>(jsonRes['instance_id']),
    cover: asT<String>(jsonRes['cover']),
    user: User.fromJson(asT<Map<String, dynamic>>(jsonRes['user'])),
    content_type: asT<String>(jsonRes['content_type']),
    like_num: asT<int>(jsonRes['like_num']),
    comment_num: asT<int>(jsonRes['comment_num']),
    title: asT<String>(jsonRes['title']),
  );

  String instance_id;
  String cover;
  User user;
  String content_type;
  int like_num;
  int comment_num;
  String title;

  Map<String, dynamic> toJson() => <String, dynamic>{
    'instance_id': instance_id,
    'cover': cover,
    'user': user,
    'content_type': content_type,
    'like_num': like_num,
    'comment_num': comment_num,
    'title': title,
  };

  @override
  String toString() {
    return json.encode(this);
  }
}